class PublishController < ApplicationController
  layout "land"
  
  before_filter :authorize, :grade
  
  #未校验数据
  def index
    @metas = Meta.find(:all, :conditions => "validate_at is null")
  end
  
  #显示待校验详细数据
  def show
    @meta = Meta.find(params[:id])
  end
  
  def show_vd
    @meta = Meta.find(params[:id])
  end
  
  #校验
  def validated_data
    meta = Meta.find(params[:id])
    meta.set_validate
    if meta.save
      flash[:notice] = "该记录通过验证！"
      redirect_to :action => "show", :id => params[:id]
    else
      flash[:notice] = "验证错误，未能通过验证！"
      redirect_to :action => "show", :id => params[:id]
    end
  end
  
  def cancel_validate
    meta = Meta.find(params[:id])
    meta.no_validate
    if meta.save
      flash[:notice] = "该记录被取消验证！"
      redirect_to :action => "show_vd", :id => params[:id]
    end
  end
  
  def next_data
  @meta = Meta.find(:first, :conditions => ["id > ? and validate_at is null",params[:id]])
    if @meta
      redirect_to :action => "show", :id => @meta
    else
      flash[:notice] = "后面已经没有未验证记录！"
      redirect_to :action => "show", :id => params[:id]
    end
  end
  
  def validated
    @meta_pages, @metas = paginate :metas, :per_page => 10, :conditions => "validate_at is not null"
  end
  
  def next_validated_data_after
    @meta = Meta.find(:first, :conditions => ["id > ? and validate_at is not null",params[:id]])
    if @meta
      redirect_to :action => "show_vd", :id => @meta
    else
      flash[:notice] = "后面已经没有验证记录！"
      redirect_to :action => "show_vd", :id => params[:id]
    end
  end
end
